import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

const pathSrc = path.resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@/': `${pathSrc}/`
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/element/index.scss" as *;`
      }
    }
  },
  plugins: [
    vue(),
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: 'sass'
        })
      ],
      dts: path.resolve(pathSrc, 'components.d.ts')
    }),
    eslintPlugin({
      cache: false,
      include: ['src/**/*.vue', 'src/**/*.js'] // 检查的文件
    })
  ],
  server: {
    host: '0.0.0.0', //解决“vite use `--host` to expose”
    port: 8088,
    open: true,
    proxy: {
      '/java': {
        target: 'https://dd-dev.lecarlink.com/', // 测试环境
        changeOrigin: true,
        rewrite: path => path.replace(/^\/java/, '')
      }
    }
  }
})
